<template>
  <div id="user">
    <div class="user-let-from">
      <!-- //Letfrom高级组件 -->
      <PageSearch
        :fromConfig="fromConfig"
        @resetBtnClick="handleResetClick"
        @queryBtnClick="handleQueryClick"
      />
    </div>
    <div class="content">
      <PageContent
        :contentTableConfig="contentTableConfig"
        pageName="users"
        ref="pageContentRef"
        @newBtnClick="newBtnClick"
        @editBtnClick="editBtnClick"
      ></PageContent>

      <PageModal
        :Modalconfig="modalConfigRef"
        ref="pageModalRef"
        :defaultInfo="defaultInfo"
        pageName="users"
      ></PageModal>
    </div>
  </div>
</template>

<script lang="ts">
import { computed, defineComponent, ref } from "vue";
import { fromConfig } from "./config/user.config";
import PageSearch from "@/components/page-search/index";
import "@/store/mian/system/system";
import { usePageSeach } from "@/hooks/usePageSeach";
import { contentTableConfig } from "./config/content.config";
import PageContent from "@/components/page-content/index";
import LetForm from "@/base-ui/from";
import { Modalconfig } from "./config/modal.config";
import PageModal from "@/components/page-modal";
import { userModal } from "@/hooks/userModal";
import { useStore } from "vuex";

export default defineComponent({
  components: {
    PageSearch,
    PageContent,
    LetForm,
    PageModal,
  },
  name: "user",
  setup(props, { emit }) {
    //pageModal相关hook逻辑
    const newCallback = () => {
      const passwordItem = Modalconfig.fromItems.find(
        (item) => item.field === "password"
      );
      passwordItem!.isHadden = false;
    };
    const editBtnback = () => {
      const passwordItem = Modalconfig.fromItems.find(
        (item) => item.field === "password"
      );
      passwordItem!.isHadden = true;
    };

    const [pageContentRef, handleResetClick, handleQueryClick] = usePageSeach();
    const [pageModalRef, defaultInfo, newBtnClick, editBtnClick] = userModal(
      newCallback,
      editBtnback
    );

    //动态添加列表和部门
    const store = useStore();
    const modalConfigRef = computed(() => {
      // const departmentItem = Modalconfig.fromItems.find(
      //   (item) => item.field === "departmentId"
      // );
      // console.log(store.state.entireDepartment);

      // departmentItem!.options = store.state.entireDepartment.map((item: any) => {
      //   return { title: item.name, value: item.id };
      // });

      // const roleItem = Modalconfig.fromItems.find(
      //   (item) => item.field === "roleId"
      // );
      // roleItem!.options = store.state.entireRole.map((item: any) => {
      //   return { title: item.name, value: item.id };
      // });
      return Modalconfig;
    });

    return {
      fromConfig,
      contentTableConfig,
      pageContentRef,
      handleResetClick,
      handleQueryClick,
      modalConfigRef,
      PageModal,
      pageModalRef,
      defaultInfo,
      newBtnClick,
      editBtnClick,
    };
  },
});
</script>

<style scoped lang="less">
.content {
  padding: 20px 60px;
  background-color: #fff;
  margin-top: 20px;
  .user-con-header {
    text-align: left;
    padding: 0px 10px 10px 0;
  }
}
</style>
